﻿#region Copyright Notice
// 
// 
//  
//  Copyright (c) 2009-2011 Anindya Chatterjee
//  
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//  
//      http://www.apache.org/licenses/LICENSE-2.0
//  
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
// 
// 
#endregion
namespace AbstractClass.NPerf.Framework
{
    /// <summary>
    /// Provides a collection of static methods that implement
    /// the most common assertions used in performance test.
    /// </summary>
    public static class Assert
    {
        /// <summary>
        /// Applies a constraint to an actual value, succeeding if the constraint is satisfied 
        /// and throwing an assertion exception on failure.
        /// </summary>
        /// <param name="value">The actual value obtain from test.</param>
        /// <param name="constraint">The constraint to apply on the actual value.</param>
        /// <remarks>It compares the values up to two decimal places.</remarks>
        /// <example>
        /// <code>
        /// 
        /// [PerfTest]
        /// public void AssertTest()
        /// {
        ///    Assert.That(The.MemoryUsageOf(TestMethod), Is.GreaterThan(6));
        ///
        ///    Assert.That(The.CPUUsageOf(TestMethod), Is.GreaterThan(46));
        ///
        ///    Assert.That(The.HitCountOf(TestMethod), Is.InBetween(10, 30));
        ///
        ///    Assert.That(The.DurationOf(TestMethod), Is.GreaterThan(2000));
        ///
        ///    Assert.That(The.DurationOf(TestMethod), Is.GreaterThan(The.DurationOf(AnotherTestMethod)));
        /// }
        /// 
        /// 
        /// public void TestMethod()
        /// {
        ///    var source1 = (Bitmap)Image.FromFile(@"C:\Users\Public\Pictures\Sample Pictures\Desert.jpg");
        ///    var bm = new Bitmap(source1.Width, source1.Height);
        ///
        ///    for (int i = 0; i &lt; 1; i++)
        ///    {
        ///        for (int y = 0; y &lt; bm.Height; y++)
        ///        {
        ///            for (int x = 0; x &lt; bm.Width; x++)
        ///            {
        ///                Color c = source1.GetPixel(x, y);
        ///                var luma = (int)(c.R * 0.3 + c.G * 0.59 + c.B * 0.11);
        ///                bm.SetPixel(x, y, Color.FromArgb(luma, luma, luma));
        ///            }
        ///        }
        ///    }
        /// }
        /// 
        /// 
        /// public void AnotherTestMethod()
        /// {
        ///     Console.WriteLine("Another Test");
        /// }
        /// 
        /// </code>
        /// </example>
        public static void That(object value, Constraint constraint)
        {
            constraint.Evaluate(value);
        }
    }
}